Skip to content

Add Tacotron2 loss function #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 26, 2021
Merged

Conversation

yangarbiter
Copy link
Contributor

@yangarbiter yangarbiter commented Jul 10, 2021

The main Tacotron2 model is in #1621. Since that PR is already too large, I'll put the Tacotron2 loss and it's tests in the example directory temporary. We should discuss more on where to put this loss function (likely the same file as Tacotron2's model).

@yangarbiter yangarbiter marked this pull request as draft July 10, 2021 00:24
@yangarbiter yangarbiter force-pushed the tacotron2_loss branch 2 times, most recently from f65959d to b72489c Compare July 12, 2021 16:39

class Tacotron2Loss(nn.Module):
"""Tacotron2 loss function adapted from:
https://github.com/NVIDIA/DeepLearningExamples/blob/master/PyTorch/SpeechSynthesis/Tacotron2/tacotron2/loss_function.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add a reference to the original paper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out. I've addressed it here.

@@ -0,0 +1,73 @@
# *****************************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to put this with the Tacotron2 model files for now, and same goes for the unit test files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the internal document, it appears that we should implement it in examples folder first. We can then discuss whether we want to merge it into the core later on.
Please let me know how you think about it. :)
Thanks.

class Tacotron2LossTest(unittest.TestCase, TempDirMixin):

dtype = torch.float64
device = "cpu"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why only cpu is being tested?

Copy link
Contributor Author

@yangarbiter yangarbiter Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've add GPU tests here and here.
Thanks for pointing it out!

Copy link
Contributor

@vincentqb vincentqb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move all the files related to the loss (e.g. loss_function.py and tests) in a subfolder examples/pipeline_tacotron2/loss/

(2) predicted mel spectrogram after the postnet (mel_specgram_postnet)
with shape (n_batch, n_mel, n_time), and
(3) the stop token prediction (gate_out) with shape (n_batch).
targets (tuple of two Tensors): The ground truth mel spectrogram (n_batch, n_mel, n_time) and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we write `(batch, mel, time), see here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
Addressed here

@yangarbiter
Copy link
Contributor Author

Following @vincentqb's suggestion, I've also run the code through black.

)


class Tacotron2LossTest(unittest.TestCase, TempDirMixin):
Copy link
Contributor

@vincentqb vincentqb Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the convention we have for testing cpu/gpu, and torchscript/autograd.

  • one base class for torchscript + two subclasses for cpu/gpu
  • one base class for autograd + two subclasses for cpu/gpu

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a test that validates the shape of the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion.
The shape test is here.
And the base class and subclasses is also addressed in the same commit.

Comment on lines 196 to 197
if __name__ == "__main__":
unittest.main()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this as we do not have this in test files anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, it is removed.



def _get_inputs(dtype, device):
n_mel, n_batch, max_mel_specgram_length = 3, 2, 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these seem very small and are not representative of a typical tensor shape. please make n_mel and _max_mel_specgram_length larger, following examples from the other tests.

@yangarbiter yangarbiter force-pushed the tacotron2_loss branch 2 times, most recently from 5b9942b to 1e16e29 Compare July 14, 2021 20:00
Copy link
Contributor

@vincentqb vincentqb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @carolineechen @mthrok -- do you have any other feedback?

@yangarbiter yangarbiter marked this pull request as ready for review July 15, 2021 16:58
Copy link
Contributor

@mthrok mthrok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you like to treat the test? We can run them as a a part of CI.
Also can you document how to run the test?

@yangarbiter
Copy link
Contributor Author

yangarbiter commented Jul 22, 2021

How would you like to treat the test? We can run them as a a part of CI.

Yes, I think it is a good idea to run them as part of CI. Could you direct me on how to do that properly?
Thanks.

Should I edit the code here by adding

cd ../examples/pipeline_tacotron2/
pytest pytest "${args[@]}" .
cd ../../test

I use the whole directory (pipeline_tacotron2) because there are going to be tests for text utilities too.

Also can you document how to run the test?

Sure, I've added a short description at examples/pipeline_tacotron2/README.md

@mthrok
Copy link
Contributor

mthrok commented Jul 26, 2021

How would you like to treat the test? We can run them as a a part of CI.

Yes, I think it is a good idea to run them as part of CI. Could you direct me on how to do that properly?
Thanks.

Should I edit the code here by adding

cd ../examples/pipeline_tacotron2/
pytest pytest "${args[@]}" .
cd ../../test

I use the whole directory (pipeline_tacotron2) because there are going to be tests for text utilities too.

Also can you document how to run the test?

Sure, I've added a short description at examples/pipeline_tacotron2/README.md

Ideally, we want to run the test in a separate job, but for a starter, this is good. You do not need "${args[@]}" as that is mostly intended for unit test. I would simply add -v. i.e. pytest -v .

@yangarbiter
Copy link
Contributor Author

How would you like to treat the test? We can run them as a a part of CI.

Yes, I think it is a good idea to run them as part of CI. Could you direct me on how to do that properly?
Thanks.
Should I edit the code here by adding

cd ../examples/pipeline_tacotron2/
pytest pytest "${args[@]}" .
cd ../../test

I use the whole directory (pipeline_tacotron2) because there are going to be tests for text utilities too.

Also can you document how to run the test?

Sure, I've added a short description at examples/pipeline_tacotron2/README.md

Ideally, we want to run the test in a separate job, but for a starter, this is good. You do not need "${args[@]}" as that is mostly intended for unit test. I would simply add -v. i.e. pytest -v .

Thanks for the comment.
The tests are add in .circleci/unittest/linux/scripts/run_test.sh and .circleci/unittest/windows/scripts/run_test.sh.

)


def skipIfNoCuda(test_item):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add #TODO: Find a way to de-duplicate this utility and reuse the original one from "test/torchaudio_unittest"

Looks like multiple utilities are duplicated, and this soon becomes unmanageable. Can you modify PYTHONPATH to include the <repo_root>/test/ directory so that you can import?

Actually, I remembered that example directories are exposed in unit tests.

import os
import sys
sys.path.append(
os.path.join(
os.path.dirname(__file__),
'..', '..', '..', 'examples'))

Can you move the test implementations into test/torchaudio_unittest/example directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I've moved the test implementations to test/torchaudio_unittest/example/tacotron2.

@yangarbiter yangarbiter force-pushed the tacotron2_loss branch 4 times, most recently from 62e4727 to bd6684a Compare July 26, 2021 19:58
@yangarbiter yangarbiter merged commit 1b52e72 into pytorch:master Jul 26, 2021
nateanl pushed a commit to nateanl/audio that referenced this pull request Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants